/* Replication Code for Mattiacci and Jones
"Restoring Legitimacy: Public Diplomacy Campaigns in Civil Wars"
International Studies Quarterly */


*Please set your directory to where the data file is located
cd ""
use "Mattiacci_Jones20_Replication.dta"

*countries that never engage in PDCs: 9, 15%
tab gwnoa if gov_PDC_freq == 0 & year < 2011

*countries that always engage in PDCs: 29, 48%
tab gwnoa if gov_PDC_freq == 1  & year < 2011

*countries that sometimes engage in PDCs: 22, 37%
tab gwnoa if gov_PDC_freq > 0 & gov_PDC_freq < 1  & year < 2011


***determine variation in PGM violence when government is restrained
tab militiatarg_max if gov_civ_log == 0 /* 243 total cases, 87 with militia targeting, 156 without */

***determine variation in PGM violence when government is NOT restrained
tab militiatarg_max if gov_civ_log  >0 /* 108 total cases, 78 with militia targeting, 30 without */

********************************
***** Models for Main Text *****
********************************


**** Model 1, Main Text
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	lgov_death  USdefense flow_tot ///
	polwing ///
	time time2 time3  ///
	, vce(cl gwnoa)
	estat ic
	
set more off
margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	time time2 time3)  
	

*********************************
***** Figures for Main Text *****
*********************************


***** generate density for lgov_civ
kdensity gov_civ_log, generate(gov_dens_x gov_dens_y)

*shift density curve down so it will fit in marginal effect plot
gen gov_dens_ys = gov_dens_y - 1

*restrict range of x axis in density plot to correspond with observed min/max of government one-sided violence
gen gov_dens_xr = gov_dens_x
replace gov_dens_xr = . if gov_dens_xr < 0
replace gov_dens_xr = . if gov_dens_xr > 8

***** Plot Marginal Effect of Militia Targeting
set more off
margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	time time2 time3)  


marginsplot,  ///
	plotop(ms(i) msize(vsmall) mc(gs0) lc(gs0)) ciop(lc(gs0) msize(small)) ///
	scheme(s2mono) graphregion(color(white)  icolor(none))  ///
	xtitle("Civilians Killed by Government (log)") ytitle("Marginal Effect of Militia Targeting") title("The Conditional Effect of Militia Targeting")  ///
	addplot(line gov_dens_ys gov_dens_xr , lw(vthin) lp(solid) lc(gs3)  ///
		legend(off))
		

*******************************
***** Models for Appendix *****
*******************************

***** Correlation table

*uncomment and run the following line to install the Corrtex package to produce the correlation table
*net install "corrtex"
corrtex  militiatarg_max gov_civ_log reb_civ_log polwing ///
 reb_PDC gdppc_l terrcontr bd_sum_log polity2 lgov_death ///
 USdefense flow_tot, file(auto) land replace
 

***** Bilateral visits, Model 1
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	bi_any ///
	time time2 time3 ///
	, vce(cl gwnoa)
		estat ic


margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing ///
	bi_any ///
	time time2 time3)  


***** Intervention in favor of the government, Model 2
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	us_govint rusch_govint ///
	time time2 time3 ///
	, vce(cl gwnoa)
		estat ic

margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing ///
	us_govint rusch_govint ///
	time time2 time3)  

	
***** Terrorisit designation Model 3

logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	terr_group ///
	time time2 time3  ///
	, vce(cl gwnoa)
		estat ic

margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing ///
	terr_group ///
	time time2 time3)  

	
***** Using the State Department's human rights Model 4
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	lgov_death  USdefense flow_tot ///
	polwing ///
	PTS_Sm ///
	time time2 time3  ///
	, vce(cl gwnoa)
		estat ic

margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	PTS_Sm ///
	time time2 time3)  
	
	
***** Intervv instead of USdefense variable  Model 5
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death   flow_tot ///
	polwing  ///
	intervv  ///
	time time2 time3 ///
	, vce(cl gwnoa)
		estat ic
	
margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death   flow_tot ///
	polwing ///
	intervv ///
	time time2 time3)  
	

***** PCT agree US at UNGA, Model 6
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	lPctAgreeUS   /// 
	time time2 time3 ///
	, vce(cl gwnoa)
	estat ic

margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing ///
	lPctAgreeUS /// 
	time time2 time3)  
	
	
***** Absolute difference, at UNGA, Model 7
 
 logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	absidealdiff   /// 
	time time2 time3 ///
	, vce(cl gwnoa)
	estat ic

margins , dydx(militiatarg_max) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing ///
	absidealdiff /// 
	time time2 time3)  
	


***** Oil and Gas Exports, Model 8
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	loilgas_ex ///
	time time2 time3  ///
	, vce(cl gwnoa)	
estat ic

margins , dydx(militiatarg) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	 polwing loilgas_ex ///
	time time2 time3 ) 
	

***** Social Media, Model 9

logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	soc_med ///
	time time2 time3  ///
	, vce(cl gwnoa)
estat ic

margins , dydx(militiatarg) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	 polwing soc_med ///
	time time2 time3 	) 

	
	
***** Dummy for Government Targeting, Model 10
logit f_gov_PDC i.militiatarg_max##i.gciv_dum reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	time time2 time3  ///
	, vce(cl gwnoa)	
estat ic

margins , dydx(militiatarg) at(gciv_dum = (0 1) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	 polwing  ///
	time time2 time3 	) 

		
***** Model with count of previous PDCs in conflict episode, Model 11
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing f_gov_PDC_counter ///
	time time2 time3  ///
	, vce(cl gwnoa)
estat ic

margins , dydx(militiatarg) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	 polwing f_gov_PDC_counter ///
	time time2 time3 	) 

***** Legal Wing, Model 12 
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	 legal2 ///
	time time2 time3  ///
	, vce(cl gwnoa)
estat ic

margins , dydx(militiatarg) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	 legal2  ///
	time time2 time3 	) 
	
	
***** Moving average of tradeflow, Model 13
logit f_gov_PDC i.militiatarg_max##c.gov_civ_log reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot_ma ///
	 polwing ///
	time time2 time3  ///
	, vce(cl gwnoa)
	estat ic


margins , dydx(militiatarg) at(gov_civ_log = (0(.1)8) ///
	(median)  ///
	reb_civ_log reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot_ma ///
	 polwing  ///
	time time2 time3 	) 

	
***** Interaction of Government and Rebel Targeting Model 14
set more off
logit f_gov_PDC i.militiatarg_max c.gov_civ_log##c.reb_civ_log ///
    reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	polwing  ///
	time time2 time3  ///
	, vce(cl gwnoa)
	estat ic
	
margins , dydx(gov_civ_log) at( reb_civ_log =(0(.1)10.31) ///
	(median)  ///
	  reb_PDC gdppc_l terrcontr bd_sum_log polity2 ///
	 lgov_death  USdefense flow_tot ///
	 polwing  ///
	time time2 time3 militiatarg_max = 0	) 

***Figure 1, Appendix
marginsplot,  ///
	plotop(ms(i) msize(vsmall) mc(gs0) lc(gs0)) ciop(lc(gs0) msize(small)) ///
	scheme(s2mono) graphregion(color(white)  icolor(none)) ///
	xtitle("Civilians Killed by Rebels (log)") ytitle("Probability of Government PD Campaign") title("Marginal Effect of Gov. Targeting of Civilians") scale(.8) ///
	legend(off)

